<?php
/**
 * 利用mysqli 实现事务查询
 * User: Administrator
 * Time: 2015/12/10 19:28
 */

$con = new mysqli('localhost', 'root', '', 'onethink');

if(mysqli_connect_errno()){
	echo '数据库连接出错，错误信息：'.mysqli_connect_error();
}

$con->autocommit(false); //自动提交模式设为false

$id=1;
$sql = "SELECT id,name,title FROM onethink_action where id=? for update ";
$stmt = $con->prepare($sql);
$stmt->bind_param('d',$id);
$stmt->execute();
$stmt->bind_result($id,$name, $title);
while ($stmt->fetch()) {
	echo $id.':'.$name.':'.$title.PHP_EOL;
}
$con->commit();
$con->close();